package com.grow.greenhouse.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.grow.greenhouse.domain.Equipdailynum;
import com.grow.greenhouse.domain.User;
import com.grow.greenhouse.domain.request.DailyNumRequest;
import com.grow.greenhouse.service.EquipdailynumService;
import com.grow.greenhouse.mapper.EquipdailynumMapper;
import com.grow.greenhouse.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalTime;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author 23854
* @description 针对表【equipdailynum】的数据库操作Service实现
* @createDate 2024-01-29 12:35:05
*/
@Service
public class EquipdailynumServiceImpl extends ServiceImpl<EquipdailynumMapper, Equipdailynum>
    implements EquipdailynumService{

    @Resource
    private UserService userService;

    @Override
    public List<Double> showDailyNum(DailyNumRequest dailyNumRequest, HttpServletRequest request) {
        User loginUser = userService.getLoginUser(request);
        QueryWrapper<Equipdailynum> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId",loginUser.getId());
        queryWrapper.eq("indicatorName",dailyNumRequest.getIndicatorName());
        queryWrapper.orderByAsc("time");
        int hour = LocalTime.now().getHour();
        queryWrapper.last("limit "+hour);
        return this.list(queryWrapper).stream().map(Equipdailynum::getDataValue).collect(Collectors.toList());
    }
}




